// Time.cpp : Defines the entry point for the console application.
//
// Samples

#include "tiny_log.h"

#include <ctime>

long fibonacci(int n)
{
    if (n < 3) return 1;
    return fibonacci(n - 1) + fibonacci(n - 2);
}

// need the following headers:
//     <stdio.h> <ctime> <string>
std::string getTimeStamp() {
    time_t rawtime;
    struct tm timeinfo;
    time(&rawtime);
    errno_t err = localtime_s(&timeinfo, &rawtime);
    assert(err == 0);
    char year[5], mon[3], mday[3], hour[3], minute[3], sec[3];
    sprintf_s(year,  sizeof(year), "%d", timeinfo.tm_year + 1900);
    sprintf_s(mon, sizeof(mon), "%d", timeinfo.tm_mon + 1);
    sprintf_s(mday, sizeof(mday), "%d", timeinfo.tm_mday);
    sprintf_s(hour, sizeof(hour), "%d", timeinfo.tm_hour);
    sprintf_s(minute, sizeof(minute), "%d", timeinfo.tm_min);
    sprintf_s(sec, sizeof(sec), "%d", timeinfo.tm_sec);

    std::string yearStr = std::string(year);
    std::string monStr = std::string(mon);
    if (monStr.size() == 1) monStr = "0" + monStr;
    std::string mdayStr = std::string(mday);
    if (mdayStr.size() == 1) mdayStr = "0" + mdayStr;
    std::string hourStr = std::string(hour);
    if (hourStr.size() == 1) hourStr = "0" + hourStr;
    std::string minuteStr = std::string(minute);
    if (minuteStr.size() == 1) minuteStr = "0" + minuteStr;
    std::string secStr = std::string(sec);
    if (secStr.size() == 1) secStr = "0" + secStr;
    return yearStr + '-' + monStr + '-' + mdayStr + \
        '_' + hourStr + '-' + minuteStr + '-' + secStr;
}
